<#import "../../pageTemplate.ftl" as pager>
<div class="panel-body">
    <div class="pad-btm form-inline">
        <div class="row">
            <div class="col-sm-6 table-toolbar-left"></div>
            <div class="col-sm-6 table-toolbar-right">
                <div class="form-group">
                    <select class="selectpicker" id="searchTypes" name="searchTypes" tabindex="2">
                        <option value="">请选择关联状态</option>
                        <option value="1" <#if searchTypes?? && searchTypes==1>selected="selected"</#if>>未审核</option>
                        <option value="2" <#if searchTypes?? && searchTypes==2>selected="selected"</#if>>已通过</option>
                        <option value="3" <#if searchTypes?? && searchTypes==3>selected="selected"</#if>>未通过</option>
                        <option value="4" <#if searchTypes?? && searchTypes==4>selected="selected"</#if>>已签约</option>
                    </select>
                </div>
                <#--<div class="form-group">-->
                    <#--<input id="input-search2" type="text" placeholder="输入公司名称" class="form-control" autocomplete="off">-->
                <#--</div>-->
                <div class="btn-group">
                    <button class="btn btn-default" onclick="search()">搜索</button>
                </div>
            </div>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table table-striped  table-bordered" id="dt-basic">
            <thead>
            <tr>
                <th class="text-center hidden-xs">序号</th>
                <th>公司名称</th>
                <th>绑定状态</th>
                <th class="hidden-xs">电压等级（kV）</th>
                <th>预估年电量（万kWh）</th>
                <th class="hidden-xs">户号个数</th>
                <th class="hidden-xs">用户类型</th>
                <th class="hidden-xs">客户地区</th>
                <th class="hidden-xs">状态</th>
                <th class="hidden-xs">已签约公司</th>
                <th>生成合同</th>
                <th class="hidden-xs">取消关联</th>
            </tr>
            </thead>
            <tbody>
            <#if pageData.content?? && (pageData.content?size>0)>
                <#list pageData.content as data>
                    <tr>
                    <td class="hidden-xs">${data_index+1}</td>
                    <td><a href="<@spring.url "/sale/companyInfo/show/${data.companyInfoId}"/>">${data.companyBak.companyName!}</a></td>
                    <td><#if data.companyBak.bangStatus??><#if data.companyBak.bangStatus ==1>未绑定<#elseif data.companyBak.bangStatus==2>已绑定<#else>绑定有争议</#if></#if></td>
                    <td class="hidden-xs">${data.companyBak.voltageStep!}</td>
                    <td><#if data.companyBak.elecConsumption??>${(data.companyBak.elecConsumption?number)/10000}</#if></td>
                    <td class="hidden-xs">${data.companyBak.elecAccountNum!}</td>
                    <td class="hidden-xs"><#if data.companyBak.types??><#if data.companyBak.types==1>零售用户<#else>电力用户</#if></#if></td>
                    <td class="hidden-xs">${(data.companyBak.cityParent.name)!}${(data.companyBak.currentCity.name)!}</td>
                    <td class="hidden-xs"><#if (data.companyInfo)??>
                            <#if data.companyInfo.status==1>未审核<#elseif data.companyInfo.status==2>已通过
                            <#elseif data.companyInfo.status==3>未通过<#elseif data.companyInfo.status==4>已签约</#if>
                        <#elseif data.status==1>未审核
                        <#elseif data.status==2>已通过
                        <#elseif data.status==3>未通过
                        <#else>已取消
                        </#if></td>
                    <td class="hidden-xs">${(data.companyBak.currentAgent)!}</td>
                    <td>
                        <#if (data.companyInfo)??>
                            合同已生成
                        <#elseif data.status==2>
                            <button class="btn btn-default" onclick="window.location.href='<@spring.url "/sale/companyInfo/newContract/${data.companyInfoId}" />'">生成合同</button>
                        </#if>
                    </td>
                    <td class="hidden-xs">
                        <#if (data.companyInfo)?? && data.companyInfo.status==4>
                        <#elseif data.status==2 || data.status==1>
                            <button class="btn btn-default" onclick="cancelConnect(${data.id})">取消关联</button>
                        </#if>
                    </td>
                    </tr>
                </#list>
            </#if>
            </tbody>
        </table>
    </div>
    <#--<#if pageData.content?? && (pageData.content?size>0)>-->
        <#--<@pager.p page=pageData.currentPage totalPages=pageData.totalPage functionName="pageChange"/>-->
    <#--</#if>-->
</div>
<script src="<@spring.url "/resources/plugins/datatables/jquery.dataTables.js"/>"></script>
<script src="<@spring.url "/resources/plugins/datatables/dataTables.bootstrap.js"/>"></script>
<script src="<@spring.url "/resources/plugins/datatables/dataTables.responsive.min.js"/>"></script>
<script src="<@spring.url "/resources/js/tables-datatables.js"/>"></script>
<script src="<@spring.url "/resources/plugins/bootstrap-select/bootstrap-select.min.js"/>"></script>
<script type="text/javascript">

    $('#dt-basic').dataTable( {
        "aLengthMenu": [[10, 25, 50, 100, -1], ["10", "25", "50", "100", "所有"]],
        <#if (userSetting.num1)??>
                "pageLength": ${userSetting.num1},
        </#if>
        "fnDrawCallback":function (settings) {
            //$("#dt-basic thead tr th:first").removeClass("sorting_asc");
            //$("#dt-basic tbody tr td:first").removeClass("sorting_asc");

        }
    });

    $("select[name='dt-basic_length']").change(function () {
        var selectValue = $("select[name='dt-basic_length']").val();
        $.post('<@spring.url "/sale/companyInfo/updateUserSetting" />',
                {selectValue1:selectValue},
                function (data) {
                });
    });

    function cancelConnect(applyId) {
        if (confirm("确定要取消关联吗？")){
            $.post('<@spring.url "/sale/companyInfo/cancelApply" />',
                    {applyId:applyId},
                    function (data) {
                        alert(data.message);
                        if (data.code == 1) {
                            window.location.reload();
                        }
                    });
        }
    }
    // $('#dt-basic').dataTable( {
    //     "paging": false,
    //     "searching" : false,
    //     "ordering":false,
    //     "fnDrawCallback":function (settings) {
    //     }
    // });


</script>